
// ************************************
// * GStore - Inventory System - thomasfn *
// ************************************
// CLIENTSIDE

module( "gstore_ui", package.seeall )

function CreateWindow( title, xrat, yrat, closable )
	local win = vgui.Create( "DFrame" )
	win:SetTitle( title )
	win:SetDraggable( false )
	win:ShowCloseButton( closable )
	win:SetSize( ScrW()*xrat, ScrH()*yrat )
	win:Center()
	win:MakePopup()
	return win
end

function CreateSlotPanel( p, container )
	local pn = vgui.Create( "DSlotPanel", p )
	pn:Setup( container.ItemLimit )
	local i
	for i=1, container.ItemLimit do
		local item = container.Items[ i ]
		print( "== SETTING SLOT [" .. tostring( i ) .. "] to [" .. tostring( item ) .. "]" )
		pn.Slots[ i ]:SetItem( item )
	end
	return pn
end

function CreateContainerWindow( container )
	local win = CreateWindow( container.Printname, 0.4, 0.4, true )
	local sp = CreateSlotPanel( win, container )
	sp:SetPos( 5, 30 )
	sp:SetSize( win:GetWide()-10, win:GetTall()-35 )
	return win
end

function SetupIcon( pn, item, fov )
	pn:SetModel( "models/" .. item.Model )
	local cpos = item:OBBCenter()
	local maxpoint = item:OBBMaxs()
	pn:SetCamPos( maxpoint*1.5 )
	pn:SetLookAt( cpos )
	pn:SetFOV( fov or 75 )
end

local function HUDPaint()
	for _, item in pairs( gstore.GetItems() ) do
		item:PaintHUD()
	end
end
hook.Add( "HUDPaint", "gstore.hudpaint", HUDPaint )